package com.meisupic.copyright.controller;

import com.meisupic.copyright.domain.bo.SysUser;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetailsService;

/**
 * creation wuxun
 *
 * @version V1.0
 * @Description: TODO
 * @date 2018/1/14 19:18
 */
public class BaseController {

  protected Logger logger = LoggerFactory.getLogger(this.getClass());

  @Autowired
  protected HttpServletRequest request;

  @Autowired
  protected HttpServletResponse response;

  @Autowired
  UserDetailsService userDetailsService;

  /**
   * 用户ID
   */
  protected Long getUserId() {
    return getUser().getId();
  }

  protected SysUser getUser() {
    SysUser user = (SysUser) SecurityContextHolder.getContext()
        .getAuthentication()
        .getPrincipal();
    return user;
  }
}
